package com.hanlink.dsp.ui.activities;

import android.content.Context;
import android.content.SharedPreferences;

import com.hanlink.dsp.BtDspApplication;
import com.qztech.bluetooth.BluetoothClientManager;
import com.qztech.bluetooth.ZBtDevice;
import com.qztech.sdk.model.ArchViewModel;

import org.greenrobot.eventbus.EventBus;

/**
 * @author : zhanghb
 * @date : 2019/1/25
 * @email : 2573475062@qq.com
 **/
public class DViewModel extends ArchViewModel {
    private final static String TAG = "HomeViewModel";
    private BluetoothClientManager mBluetoothClientManager;

    public DViewModel() {
        mBluetoothClientManager = BluetoothClientManager.getInstance(BtDspApplication.getInstance());
    }

    public void searchBluetooth() {
        mBluetoothClientManager.stopSearch();
        mBluetoothClientManager.searchBleDevice();
    }

    public ZBtDevice getConnectedDevice() {
        return mBluetoothClientManager.getConnectedDevice();
    }

    public void connect(String mac, String name) {
        mBluetoothClientManager.setReadData(false);
        ZBtDevice zBtDevice = new ZBtDevice();
        zBtDevice.setMac(mac);
        zBtDevice.setName(name);
        mBluetoothClientManager.connectLeDevice(zBtDevice);
    }

    public void cancelSearch() {
        mBluetoothClientManager.stopSearch();
    }

    public void disconnect() {
        mBluetoothClientManager.disconnect();
    }

    

    @Override
    protected void onCleared() {
        super.onCleared();
        EventBus.getDefault().unregister(this);
    }
}
